package com.navinfo.parkingnavi.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

/*
 *com.navinfo.parkingnavi.fragment
 *zhjch
 *2020/5/12
 *14:25
 *说明（基类fragment）
 */
public abstract class BaseFragment extends Fragment {

    protected String mTag = getClass().getName();
    protected View mFragmentView;
    protected OnBaseFragmentListener mListener;

    protected Bundle mDataBundle;//传输数据

    public void setOnBaseFragmentListener(OnBaseFragmentListener listener) {
        mListener = listener;
    }

    public interface OnBaseFragmentListener {
        void onDestroyView();
    }

    public boolean onBackPressed() {
        return false;
    }


    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        mDataBundle = getArguments();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        onDataChange(mDataBundle);
    }

    /**
     * 数据变更
     *
     * @param bundle 数据传输对象
     */
    public abstract void onDataChange(Bundle bundle);

    public String getFragmentTag() {
        return mTag;
    }

    public void onHideOrRemove(boolean bRemove) {
        if (mListener != null && bRemove)
            mListener.onDestroyView();
    }
}
